import { ecs } from "db://oops-framework/libs/ecs/ECS";
import { Role } from "../../role/Role";
import { VM } from "db://oops-framework/libs/model-view/ViewModel";
import { Leader } from "../../leader/Leader";
import { Item } from "../../item/Item";

/** 
 * 游戏帐号数据 
 * 1、管理游戏中玩家个人身份数据
 * 2、管理游戏中玩家数据
 */
@ecs.register('AccountModel')
export class AccountModelComp extends ecs.Comp {

    /** 提供MVVM组件使用的数据 */
    vm: any = {};

    /** uid */
    uid: number = 0;

    /** subid */
    subid: number = 0;

    /** 代理id */
    dailiID: number = 0;

    /** 下级好友id */
    friendID: number = 0;

    /** 主角等级 */
    level: number = 1;

    /** 金砖 */
    jinzhuan: number = 0;

    /** 梦魇晶石 */
    mengyanjingshi: number = 0;
    /** 战斗力 */
    battlePower: number = 0;

    /** 我拥有的角色 - 建议：独立出一个对象不要把玩家自己用ROLE */
    leader: Leader = null!;

    /** 我拥有的角色 */
    roles: Map<number, Role> = new Map();
    /** 我出阵的角色 */
    battles: Map<number, Role> = new Map();
    /** 仓库 */
    bag: Map<string, Item> = new Map();


    /** 首页加载完成 */
    mainLoaded: boolean = false;


    /** 金币 */
    private _coin: number = 0;
    public get coin(): number {
        return this._coin;
    }

    public set coin(v: number) {
        this._coin = v;
        this.vm["coin"] = v;
    }

    /** 元宝 */
    private _gold: number = 0;
    public get gold(): number {
        return this._gold;
    }

    public set gold(v: number) {
        this._gold = v;
        this.vm["gold"] = v;
    }
    /** 精铁:装备升级 */
    private _jingtie: number = 0;
    public get jingtie(): number {
        return this._jingtie;
    }

    public set jingtie(v: number) {
        this._jingtie = v;
        this.vm["jingtie"] = v;
    }
    vmAdd() {
        this.coin = 0;
        this.gold = 0;
        this.jingtie = 0;
        VM.add(this.vm, "Account");
    }

    vmRemove() {
        VM.remove("Account");
    }
    reset() {
        this.leader = null!;
        this.roles.clear();
        this.battles.clear();
        this.vmRemove();
        this.uid = 0;
        this.subid = 0;
        this.coin = 0;
        this.gold = 0;
        this.jingtie = 0;
    }
}